'use strict';

const {chromium, firefox} = require('playwright');
const Service = require('egg').Service;

class SearchEngineSvc extends Service {
  constructor(app) {
    super(app);
    // 搜索超时10秒
    this.SEARCH_TIMEOUT = 10000;
  }

  async sugg(kw) {
    const redis_key = 'sugg2:' + kw;
    const cache_result = await this.service.cacheSvc.get(redis_key);
    if (cache_result) {
      return cache_result;
    }

    const response = await this.ctx.curl(`https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=33639,33744,33273,31254,33691,33855&wd=${kw}&req=2&csor=2&cb=jQuery1102020617794665700417_1617852533550&_=1617852533558`);
    if (response.status == 200) {
      const data = response.data.toString();
      let regResult = data.match(/("q":"[^"]+)/g);
      if (!regResult) {
        return [];
      }
      let result = [];
      for (let i = 1; i < regResult.length; i++) {
        result.push(regResult[i].substr(5));
      }
      await this.service.cacheSvc.setex(redis_key, result, 3600 * 24);
      return result;
    } else {
      return [];
    }
  }


  /**
   * 搜索百度
   */
  async searchBaidu(kw, now_page) {
    const beginTime = Date.now();
    let topics = [];
    const page = await this.app.pptBrowser.newPage();
    try {
      await page.route('**/*', route => {
        if (route.request()
          .url()
          .includes('www.baidu.com/s?wd=')) {
          route.continue();
        } else {
          route.abort();
        }
      });
      await page.setExtraHTTPHeaders({
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        'Cache-Control': 'max-age=0',
        'Connection': 'keep-alive',
        'sec-ch-ua': '"Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36'
      });

      let page_size = 10;
      const url = `https://www.baidu.com/s?wd=${encodeURIComponent(kw)}&pn=${page_size * (now_page - 1)}&rsv_spt=1&rsv_iqid=0x9d60a8de003af168&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_dl=tb&rsv_enter=1&rsv_sug3=1&rsv_sug1=1&rsv_sug7=100&rsv_sug2=0&rsv_btype=i&inputT=348&rsv_sug4=348`;
      await page.goto(url, {waitUntil: 'domcontentloaded', timeout: this.SEARCH_TIMEOUT});
      const content_none = await page.$('.content_none');
      if (content_none) {
        return [];
      }
      await page.waitForSelector('#content_left > div', {timeout: this.SEARCH_TIMEOUT, state: 'attached'});

      const elements = await page.$$('#content_left > div');
      for (let i = 0; i < elements.length; i++) {
        const el = elements[i];

        let key;
        let content;
        let address;
        let tab = 'baidu';
        let logo = '/public/img/baidu.png';

        if (await el.$('h3')) {
          key = await el.$eval('h3', v => v.innerText);
        } else {
          key = '特殊:' + kw + i;
        }
        key = key.replace(/[^a-zA-Z0-9\u4e00-\u9fa5]/g, '');

        content = await el.evaluate(async v => v.outerHTML);
        if (content.includes('大家还在搜') ||
          content.includes('搜索智能聚合')) {
          continue;
        }
        content = content.replace(/width: ?\d{3,}px/g, '');
        if (content.includes('href="/')) {
          content = content.replace(/<a/g, '<a target="_blank"');
          content = content.replace(/href="\//g, 'href="https://www.baidu.com/');
        }
        if (await el.$('a')) {
          address = await el.$eval('a', v => v.href);
        } else {
          address = '特殊:' + kw + i;
        }

        if (key.endsWith('知乎')) {
          tab = 'zhihu';
          logo = '/public/img/zhihu.png';
        }

        topics.push({
          key,
          address,
          content,
          tab,
          logo,
        });
      }

      topics = topics.filter(v => v.address.length < 1000
        && !v.key.endsWith('出行防疫政策查询')
        && !v.key.endsWith('全网热卖')
        && !v.key.endsWith('百度地图')
        && !v.key.endsWith('新浪财经')
        && !v.key.endsWith('东方财富')
        && !v.key.endsWith('富途牛牛')
        && !v.key.endsWith('百度爱采购')
        && !v.key.endsWith('百度游戏')
        && !v.key.endsWith('挂号网')
        && !v.key.endsWith('招商加盟')
        && !v.key.endsWith('百度百聘')
        && !v.key.endsWith('闪电下载')
        && !v.key.endsWith('51下载')
        && !v.key.endsWith('极速下载')
        && !v.key.endsWith('5119下载')
        && !v.key.endsWith('知了好学')
        && !v.key.endsWith('百度健康')
        && !v.key.endsWith('百度健康问医生')
        && !v.key.endsWith('百度招聘')
        && !v.key.endsWith('查询预订')
        && !v.key.endsWith('百度股市通')
        && !v.key.endsWith('IP地址查询')
        && !v.key.endsWith('百度移动应用')
        && !v.key.endsWith('九方智投')
        && !v.key.endsWith('百家号')
        && !v.key.endsWith('滑块验证')
        && !v.key.endsWith('百度安全验证')
        && !v.key.endsWith('车票预订')
      );

      // 动态加百度css
      if (topics.length > 0) {
        let content_css = await page.$eval('#content_style', el => el.innerHTML.trim());
        content_css = content_css.replace(/width: ?\d{3,}px/g, '');
        topics[0].content = content_css + topics[0].content;
      }

    } catch (e) {
      this.logger.error(e.message);
      if (page != null) {
        await page.waitForTimeout(3000);
      }
    } finally {
      await page.close();
      const endTime = Date.now();
      this.logger.info('百度search...: ' + kw, now_page, endTime - beginTime);
      return topics;
    }
  }


  /**
   * 搜索谷歌
   */
  async searchGoogle(kw, now_page) {
    let topics = await Promise.race([
      this.searchAgencyGoogle(kw, now_page, 'https://xgoogle.xyz/'),
      this.searchAgencyGoogle(kw, now_page, 'https://search.njau.cf/extdomains/www.google.com.hk/'),
      this.searchAgencyGoogle(kw, now_page, 'https://search.aust.cf/extdomains/www.google.com.hk/'),
      this.searchAgencyGoogle(kw, now_page, 'https://gogogle.cf/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://search.ecnu.cf/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://gogogle.gq/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://txt.muxinghe.ga/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://xn--flw351e.ml/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://search.ahau.cf/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://search.ahnu.cf/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://www.qinai.ml/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://shitu.paodekuaiweixinqun.com/'),
      // this.searchAgencyGoogle(kw, now_page, 'http://google.1qi777.com/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://www.googlejxz.ml/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://google.pem.app/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://www.paddy.ml/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://search.xn--u8jta9j.tw/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://search.xn--pckl1n.tw/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://search.iwiki.uk/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://go-xyz.xyz/'),
      // this.searchAgencyGoogle(kw, now_page, 'https://g3.luciaz.me/'),
    ]);

    return topics;
  }


  /**
   * 搜索代理谷歌
   */
  async searchAgencyGoogle(kw, now_page, agency_url) {
    let beginTime = Date.now();
    if (agency_url.endsWith('/')) {
      agency_url = agency_url.substr(0, agency_url.length - 1);
    }

    let topics = [];
    const page = await this.app.pptBrowser.newPage();
    try {
      await page.route('**/*', route => {
        if (route.request()
          .url()
          .includes('search?q=')) {
          route.continue();
        } else {
          route.abort();
        }
      });
      await page.setExtraHTTPHeaders({'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8'});
      let page_size = 20;
      let url = `${agency_url}/search?q=${encodeURIComponent(kw)}&start=${page_size * (now_page - 1)}&num=${page_size}`;
      await page.goto(url, {waitUntil: 'domcontentloaded', timeout: this.SEARCH_TIMEOUT});

      await page.waitForSelector('#botstuff table > tbody > tr,.GNJvt.ipz2Oe', {
        state: 'attached',
        timeout: this.SEARCH_TIMEOUT
      });

      let elements = await page.$$('.v7W49e > div');
      if (elements.length < 2) {
        elements = await page.$$('.TzHB6b.cLjAic.K7khPe');
        if (elements.length < 2) {
          elements = await page.$$('.Ww4FFb.vt6azd.tF2Cxc');
          if (elements.length < 2) {
            elements = await page.$$('.v7W49e > div');
          }
        }
      }

      for (let i = 0; i < elements.length; i++) {
        const el = elements[i];

        let key;
        let content;
        let address;
        let tab = 'tsou';
        let logo = '/public/img/tsousou.png';

        if (await el.$('h3')) {
          key = await el.$eval('h3', v => v.innerText);
        } else if (await el.$('h2')) {
          key = await el.$eval('h2', v => v.innerText);
        } else {
          key = '特殊:' + kw + i;
        }
        key = key.replace(/[^a-zA-Z0-9\u4e00-\u9fa5]/g, '');
        if (key.endsWith('知乎专栏')) {
          key = key.substr(0, key.length - 2);
        }

        content = await el.evaluate(async v => v.outerHTML);
        content = content.replace(/width: ?\d{3,}px/g, '');
        content = content.replace(/<a/g, '<a target="_blank"');
        if (content.includes('href="/')) {
          content = content.replace(/href="\//g, 'href="https://www.google.com/');
        }
        if (content.includes(' ping="')) {
          content = content.replace(/ ping=".+?"/g, '');
        }

        if (await el.$('a')) {
          address = await el.$eval('a', v => v.href);
          if (address.includes('zhihu.com')) {
            tab = 'zhihu';
            logo = '/public/img/zhihu.png';
          }
        } else {
          address = '#';
        }


        topics.push({
          key,
          address,
          content,
          tab,
          logo
        });
      }

      if (topics.length > 1) {
        topics = this.filterGoogleTopics(topics);
      }

      // 动态加谷歌css
      if (topics.length > 0) {
        if (await page.$('.s6JM6d > style')) {
          let content_css = await page.$eval('.s6JM6d > style', el => el.outerHTML);
          content_css = content_css.replace(/width: ?\d{3,}px/g, '');
          topics[0].content = content_css + topics[0].content;
        }
      }

      let endTime = Date.now();
      this.logger.info(`[${kw}] [${now_page}] google success ${agency_url}  爬取google数据成功, 数量为: [${topics.length}],  spend ${endTime - beginTime}ms`);
    } catch (e) {
      if (e.message.includes('intro')) {
        this.logger.error(e);
      } else {
        // this.logger.error(e.message);
      }
      await page.waitForTimeout(this.SEARCH_TIMEOUT);
    } finally {
      if (topics.length < 5) {
        await page.waitForTimeout(5000);
      }
      await page.close();
      return topics;
    }
  }


  /**
   * 搜索知乎
   */
  async searchZhihu(kw) {
    const beginTime = Date.now();
    let topics = [];
    const browser = await firefox.launch({headless: true});
    try {
      const page = await browser.newPage();
      let url = `https://www.zhihu.com/search?type=content&q=${encodeURIComponent(kw)}`;
      await page.goto(url, {waitUntil: 'domcontentloaded', timeout: this.SEARCH_TIMEOUT});
      await page.waitForSelector('.SearchResult-Card');

      console.time(`${kw} autoScroll`);
      await this.autoScroll(page, 3500);
      console.timeEnd(`${kw} autoScroll`);

      const elements = await page.$$('.List div.Card');
      for (let i = 0; i < elements.length; i++) {
        const el = elements[i];

        let key;
        let content;
        let address;
        let tab = 'zhihu';
        let logo = '/public/img/zhihu.png';

        if (await el.$('h2')) {
          key = await el.$eval('h2', v => v.innerText);
        } else {
          key = '特殊:' + kw + i;
        }
        key = key.replace(/[^a-zA-Z0-9\u4e00-\u9fa5]/g, '');

        content = await el.evaluate(async v => v.outerHTML);
        if (content.includes('href="/')) {
          content = content.replace(/href="\//g, 'href="https://www.zhihu.com/');
        }
        if (await el.$('a')) {
          address = await el.$eval('a', v => v.href);
        }

        if (address) {
          topics.push({
            key,
            content,
            address,
            tab,
            logo
          });
        } else {
          console.error(i, key, '没有address');
        }
      }

    } catch (e) {
      this.logger.error(e);
    } finally {
      const endTime = Date.now();
      this.logger.info('知乎search...: ' + kw, endTime - beginTime);
      await browser.close();
      return topics;
    }

  }


  async autoScroll(page, bottom_height) {
    await page.evaluate(async (bottom_height) => {
      await new Promise((resolve, reject) => {
        let totalHeight = 0;
        let distance = 700;
        let timer = setInterval(() => {
          let scrollHeight = document.body.scrollHeight;
          window.scrollBy(0, distance);
          totalHeight += distance;

          if (totalHeight > bottom_height) {
            clearInterval(timer);
            resolve();
          } else if (totalHeight >= scrollHeight) {
            clearInterval(timer);
            resolve();
          }
        }, 30);
      });
    }, bottom_height);
  }


  filterGoogleTopics(topics) {
    return topics.filter(v => v.key.length > 1
      && v.key != '地点'
      && v.key != '地图'
      && !v.key.includes('焦点新闻')
      && !v.key.includes('视频')
      && !v.key.includes('本地搜索结果')
      && !v.key.includes('图片搜索结果')
      && !v.key.includes('Imagesfor')
      && !v.key.includes('TikTokSearch')
      && !v.key.includes('其他用户还问了以下问题')
      && !v.key.includes('Peoplealsoask')
      && !v.key.includes('维基')
      && !v.key.includes('约个妞')
      && !v.key.includes('六四')
      && !v.key.includes('64事件')
      && !v.key.includes('天安门')
      && !v.key.includes('天安門')
      && !v.key.includes('近平')
      && !v.key.includes('反习')
      && !v.key.includes('习大大')
      && !v.key.includes('习特厚')
      && !v.key.includes('习特勒')
      && !v.key.includes('习特厚')
      && !v.key.includes('习奥塞斯库')
      && !v.key.includes('习鞑靼')
      && !v.key.includes('习维尼')
      && !v.key.includes('习核心')
      && !v.key.includes('习包子')
      && !v.key.includes('庆丰包子')
      && !v.key.includes('大撒币')
      && !v.key.includes('习背书')
      && !v.key.includes('毛泽东')
      && !v.key.includes('邓小平')
      && !v.key.includes('共产党')
      && !v.key.includes('人权')
      && !v.key.includes('威权')
      && !v.key.includes('专制')
      && !v.key.includes('反共')
      && !v.key.includes('集权')
      && !v.key.includes('庆丰帝')
      && !v.key.includes('平近习')
      && !v.key.includes('xjp')
      && !v.key.includes('习太子')
      && !v.key.includes('习明泽')
      && !v.key.includes('老习')
      && !v.key.includes('温家宝')
      && !v.key.includes('温加宝')
      && !v.key.includes('温x')
      && !v.key.includes('温jia宝')
      && !v.key.includes('温宝宝')
      && !v.key.includes('温加饱')
      && !v.key.includes('温加保')
      && !v.key.includes('张培莉')
      && !v.key.includes('温云松')
      && !v.key.includes('温如春')
      && !v.key.includes('温jb')
      && !v.key.includes('胡温')
      && !v.key.includes('胡x')
      && !v.key.includes('胡jt')
      && !v.key.includes('胡boss')
      && !v.key.includes('胡总')
      && !v.key.includes('胡王八')
      && !v.key.includes('hujintao')
      && !v.key.includes('胡jintao')
      && !v.key.includes('胡j涛')
      && !v.key.includes('胡惊涛')
      && !v.key.includes('胡景涛')
      && !v.key.includes('胡紧掏')
      && !v.key.includes('湖紧掏')
      && !v.key.includes('胡紧套')
      && !v.key.includes('锦涛')
      && !v.key.includes('hjt')
      && !v.key.includes('胡派')
      && !v.key.includes('胡主席')
      && !v.key.includes('刘永清')
      && !v.key.includes('胡海峰')
      && !v.key.includes('胡海清')
      && !v.key.includes('江泽民')
      && !v.key.includes('民泽江')
      && !v.key.includes('江胡')
      && !v.key.includes('江哥')
      && !v.key.includes('江主席')
      && !v.key.includes('江书记')
      && !v.key.includes('江浙闽')
      && !v.key.includes('江沢民')
      && !v.key.includes('江浙民')
      && !v.key.includes('择民')
      && !v.key.includes('则民')
      && !v.key.includes('茳泽民')
      && !v.key.includes('zemin')
      && !v.key.includes('ze民')
      && !v.key.includes('老江')
      && !v.key.includes('老j')
      && !v.key.includes('江core')
      && !v.key.includes('江x')
      && !v.key.includes('江派')
      && !v.key.includes('江zm')
      && !v.key.includes('jzm')
      && !v.key.includes('江戏子')
      && !v.key.includes('江蛤蟆')
      && !v.key.includes('江某某')
      && !v.key.includes('江贼')
      && !v.key.includes('江猪')
      && !v.key.includes('江氏集团')
      && !v.key.includes('江绵恒')
      && !v.key.includes('江绵康')
      && !v.key.includes('王冶坪')
      && !v.key.includes('江泽慧')
      && !v.key.includes('平小邓')
      && !v.key.includes('xiao平')
      && !v.key.includes('邓xp')
      && !v.key.includes('邓晓平')
      && !v.key.includes('邓朴方')
      && !v.key.includes('邓榕')
      && !v.key.includes('邓质方')
      && !v.key.includes('猫泽东')
      && !v.key.includes('猫则东')
      && !v.key.includes('猫贼洞')
      && !v.key.includes('毛zd')
      && !v.key.includes('毛zx')
      && !v.key.includes('z东')
      && !v.key.includes('ze东')
      && !v.key.includes('泽d')
      && !v.key.includes('zedong')
      && !v.key.includes('毛太祖')
      && !v.key.includes('毛相')
      && !v.key.includes('主席画像')
      && !v.key.includes('改革历程')
      && !v.key.includes('朱镕基')
      && !v.key.includes('朱容基')
      && !v.key.includes('朱镕鸡')
      && !v.key.includes('朱容鸡')
      && !v.key.includes('朱云来')
      && !v.key.includes('李鹏')
      && !v.key.includes('李peng')
      && !v.key.includes('里鹏')
      && !v.key.includes('李月月鸟')
      && !v.key.includes('李小鹏')
      && !v.key.includes('李小琳')
      && !v.key.includes('华主席')
      && !v.key.includes('华国')
      && !v.key.includes('国锋')
      && !v.key.includes('国峰')
      && !v.key.includes('锋同志')
      && !v.key.includes('白春礼')
      && !v.key.includes('薄熙来')
      && !v.key.includes('薄一波')
      && !v.key.includes('蔡赴朝')
      && !v.key.includes('蔡武')
      && !v.key.includes('曹刚川')
      && !v.key.includes('常万全')
      && !v.key.includes('陈炳德')
      && !v.key.includes('陈德铭')
      && !v.key.includes('陈建国')
      && !v.key.includes('陈良宇')
      && !v.key.includes('陈绍基')
      && !v.key.includes('陈同海')
      && !v.key.includes('陈至立')
      && !v.key.includes('戴秉国')
      && !v.key.includes('丁一平')
      && !v.key.includes('董建华')
      && !v.key.includes('杜德印')
      && !v.key.includes('杜世成')
      && !v.key.includes('傅锐')
      && !v.key.includes('郭伯雄')
      && !v.key.includes('郭金龙')
      && !v.key.includes('贺国强')
      && !v.key.includes('胡春华')
      && !v.key.includes('耀邦')
      && !v.key.includes('华建敏')
      && !v.key.includes('黄华华')
      && !v.key.includes('黄丽满')
      && !v.key.includes('黄兴国')
      && !v.key.includes('回良玉')
      && !v.key.includes('贾庆林')
      && !v.key.includes('贾廷安')
      && !v.key.includes('靖志远')
      && !v.key.includes('李长春')
      && !v.key.includes('李春城')
      && !v.key.includes('李建国')
      && !v.key.includes('李克强')
      && !v.key.includes('李岚清')
      && !v.key.includes('李沛瑶')
      && !v.key.includes('李荣融')
      && !v.key.includes('李瑞环')
      && !v.key.includes('李铁映')
      && !v.key.includes('李先念')
      && !v.key.includes('李学举')
      && !v.key.includes('李源潮')
      && !v.key.includes('栗智')
      && !v.key.includes('梁光烈')
      && !v.key.includes('廖锡龙')
      && !v.key.includes('林树森')
      && !v.key.includes('林炎志')
      && !v.key.includes('林左鸣')
      && !v.key.includes('令计划')
      && !v.key.includes('柳斌杰')
      && !v.key.includes('刘奇葆')
      && !v.key.includes('刘少奇')
      && !v.key.includes('刘延东')
      && !v.key.includes('刘云山')
      && !v.key.includes('刘志军')
      && !v.key.includes('龙新民')
      && !v.key.includes('路甬祥')
      && !v.key.includes('罗箭')
      && !v.key.includes('吕祖善')
      && !v.key.includes('马飚')
      && !v.key.includes('马恺')
      && !v.key.includes('孟建柱')
      && !v.key.includes('欧广源')
      && !v.key.includes('强卫')
      && !v.key.includes('沈跃跃')
      && !v.key.includes('宋平顺')
      && !v.key.includes('粟戎生')
      && !v.key.includes('苏树林')
      && !v.key.includes('孙家正')
      && !v.key.includes('铁凝')
      && !v.key.includes('屠光绍')
      && !v.key.includes('王东明')
      && !v.key.includes('汪东兴')
      && !v.key.includes('王鸿举')
      && !v.key.includes('王沪宁')
      && !v.key.includes('王乐泉')
      && !v.key.includes('王洛林')
      && !v.key.includes('王岐山')
      && !v.key.includes('王胜俊')
      && !v.key.includes('王太华')
      && !v.key.includes('王学军')
      && !v.key.includes('王兆国')
      && !v.key.includes('王振华')
      && !v.key.includes('吴邦国')
      && !v.key.includes('吴定富')
      && !v.key.includes('吴官正')
      && !v.key.includes('无官正')
      && !v.key.includes('吴胜利')
      && !v.key.includes('吴仪')
      && !v.key.includes('奚国华')
      && !v.key.includes('习仲勋')
      && !v.key.includes('徐才厚')
      && !v.key.includes('许其亮')
      && !v.key.includes('徐绍史')
      && !v.key.includes('杨洁篪')
      && !v.key.includes('叶剑英')
      && !v.key.includes('由喜贵')
      && !v.key.includes('于幼军')
      && !v.key.includes('俞正声')
      && !v.key.includes('袁纯清')
      && !v.key.includes('曾培炎')
      && !v.key.includes('曾庆红')
      && !v.key.includes('曾宪梓')
      && !v.key.includes('曾荫权')
      && !v.key.includes('张德江')
      && !v.key.includes('张定发')
      && !v.key.includes('张高丽')
      && !v.key.includes('张立昌')
      && !v.key.includes('张荣坤')
      && !v.key.includes('张志国')
      && !v.key.includes('赵洪祝')
      && !v.key.includes('紫阳')
      && !v.key.includes('周生贤')
      && !v.key.includes('周永康')
      && !v.key.includes('朱海仑')
      && !v.key.includes('中南海')
      && !v.key.includes('大陆当局')
      && !v.key.includes('中国当局')
      && !v.key.includes('北京当局')
      && !v.key.includes('党产共')
      && !v.key.includes('共贪党')
      && !v.key.includes('阿共')
      && !v.key.includes('产党共')
      && !v.key.includes('公产党')
      && !v.key.includes('工产党')
      && !v.key.includes('共c党')
      && !v.key.includes('共x党')
      && !v.key.includes('共铲')
      && !v.key.includes('供产')
      && !v.key.includes('共惨')
      && !v.key.includes('供铲党')
      && !v.key.includes('供铲谠')
      && !v.key.includes('供铲裆')
      && !v.key.includes('共残党')
      && !v.key.includes('共残主义')
      && !v.key.includes('共产主义')
      && !v.key.includes('拱铲')
      && !v.key.includes('老共')
      && !v.key.includes('中共')
      && !v.key.includes('中珙')
      && !v.key.includes('中gong')
      && !v.key.includes('gc党')
      && !v.key.includes('贡挡')
      && !v.key.includes('gong党')
      && !v.key.includes('g产')
      && !v.key.includes('狗产蛋')
      && !v.key.includes('共残裆')
      && !v.key.includes('恶党')
      && !v.key.includes('邪党')
      && !v.key.includes('共产王朝')
      && !v.key.includes('裆中央')
      && !v.key.includes('土共')
      && !v.key.includes('土g')
      && !v.key.includes('共狗')
      && !v.key.includes('g匪')
      && !v.key.includes('共匪')
      && !v.key.includes('仇共')
      && !v.key.includes('政府')
      && !v.key.includes('症腐')
      && !v.key.includes('政腐')
      && !v.key.includes('政付')
      && !v.key.includes('正府')
      && !v.key.includes('政俯')
      && !v.key.includes('政f')
      && !v.key.includes('zhengfu')
      && !v.key.includes('政zhi')
      && !v.key.includes('挡中央')
      && !v.key.includes('档中央')
      && !v.key.includes('中央领导')
      && !v.key.includes('中国zf')
      && !v.key.includes('中央zf')
      && !v.key.includes('国wu院')
      && !v.key.includes('中华帝国')
      && !v.key.includes('gong和')
      && !v.key.includes('大陆官方')
      && !v.key.includes('北京政权')
      && !v.key.includes('江泽民')
      && !v.key.includes('胡锦涛')
      && !v.key.includes('温家宝')
      && !v.key.includes('习仲勋')
      && !v.key.includes('贺国强')
      && !v.key.includes('贺子珍')
      && !v.key.includes('周永康')
      && !v.key.includes('李长春')
      && !v.key.includes('李德生')
      && !v.key.includes('王岐山')
      && !v.key.includes('姚依林')
      && !v.key.includes('回良玉')
      && !v.key.includes('李源潮')
      && !v.key.includes('李干成')
      && !v.key.includes('戴秉国')
      && !v.key.includes('黄镇')
      && !v.key.includes('刘延东')
      && !v.key.includes('刘瑞龙')
      && !v.key.includes('俞正声')
      && !v.key.includes('黄敬')
      && !v.key.includes('薄熙')
      && !v.key.includes('薄一波')
      && !v.key.includes('周小川')
      && !v.key.includes('周建南')
      && !v.key.includes('温云松')
      && !v.key.includes('徐明')
      && !v.key.includes('江泽慧')
      && !v.key.includes('江绵恒')
      && !v.key.includes('江绵康')
      && !v.key.includes('李小鹏')
      && !v.key.includes('李鹏')
      && !v.key.includes('李小琳')
      && !v.key.includes('朱云来')
      && !v.key.includes('朱容基')
      && !v.key.includes('法轮功')
      && !v.key.includes('李洪志')
      && !v.key.includes('新疆骚乱')
      && !v.key.includes('反动')
      && !v.address.includes('wikipedia.')
      && !v.address.includes('www.wikiwand.com')
      && !v.address.includes('new7.storm.mg')
      && !v.address.includes('www.upmedia.mg')
      && !v.address.includes('netalert.me')
      && !v.address.includes('chinadigitaltimes.net')
      && !v.address.includes('fandom.com')
      && !v.address.includes('rfi.fr')
      && !v.address.includes('www.bbc.com/zhongwen')
      && !v.address.includes('graphics.wsj.com')
      && !v.address.includes('www.dw.com')
      && !v.address.includes('cn.nytimes.com')
      && !v.address.includes('www.hrw.org')
      && !v.address.includes('www.rfa.org')
      && !v.address.includes('cn.wsj.com')
      && !v.address.includes('www.voachinese.com')
      && !v.address.includes('ipdefenseforum.com')
      && !v.address.includes('www.storm.mg')
      && !v.address.includes('www.abc.net')
      && !v.address.includes('www.ftchinese.com')
      && !v.address.includes('www.businessweekly.com.tw')
      && !v.address.includes('tw.appledaily.com')
      && !v.address.includes('www.marxist.com')
      && !v.address.includes('context.reverso.net')
      && !v.address.includes('artsandculture.google.com')
      && !v.address.includes('.gov.tw')
      && !v.address.includes('www.twreporter.org')
      && !v.address.includes('www.zaobao.com')
      && !v.address.includes('hk01.com')
      && !v.address.includes('ntdtv.com')
    );
  }

}

module.exports = SearchEngineSvc;
